// pages/user/setmsg/setmsg.js
import { urlEncode } from '../../../utils/util.js'
import { Target, HttpUtil } from '../../../utils/http_util.js'
var config = require('../../../utils/config.js')
var utils = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:'',
    userType:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getStorage({
      key: 'userInfo',
      success(userres) {
        console.log(userres);
        that.setData({
          userInfo: userres.data
        });
      }
    })
    wx.getStorage({
      key: 'userType',
      success(res) {
        that.setData({
          userType: res.data
        });
      }
    })
  },

  loginOut:function(){
    var that =this;
    HttpUtil.get(Target.self, "wx/small/loginOut", { phone: that.data.userInfo.phone }).then(res => {
      if (res.status == '0000') {
        wx.removeStorage({
          key: 'userInfo',
          success(res) {
            wx.reLaunch({
              url: '/pages/user/user-main/main'
            })
          }
        })
      } else {
        wx.showToast({
          title: '退出异常！',
          icon: 'none',
          duration: 2000
        })
      }
    })
  }
})